/*
 * 描述： <描述>
 * 修改人： rain
 * 修改时间： 2016年10月5日
 * 项目： rainhy-webcore
 */
package com.rainhy.webcore.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import com.rainhy.webcore.holder.WebContextHolder;

/**
 * 辅助WebContextHolder类,在 request 请求时,注入 HttpServletRequest
 * 
 * @author rain
 * @version [版本号, 2016年10月5日]
 * @see [相关类/方法]
 * @since [产品/模块版本]
 */
public class WebContextHandlerInterceptor extends HandlerInterceptorAdapter {
    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
        WebContextHolder.removeCurrentRequestFromThread();
    }
    
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        WebContextHolder.bindCurrentRequestToThread(request, response);
        return true;
    }
}
